var mongoose = require("mongoose"); //引入mongoose
mongoose.connect('mongodb://xiaohu123.xyz/allData',{  useNewUrlParser: true,useUnifiedTopology: true }); //连接到mongoDB的todo数据库
//该地址格式：mongodb://[username:password@]host:port/database[?options]
//默认port为27017 

var db = mongoose.connection;
db.on('error', function callback() { //监听是否有异常
    console.log("Connection error");
});
db.once('open', function callback() { //监听一次打开
    console.log('connected!');
});

//设置模式
var ListSchema = new mongoose.Schema({
     aqi:Number,
     area:String,
     co:Number,
     co_24h:Number,
     no2:Number,
     no2_24h:Number,
     o3:Number,
     o3_24h:Number,
     o3_8h:Number,
     o3_8h_24h:Number,
     pm10:Number,
     pm10_24h:Number,
     pm2_5:Number,
     pm2_5_24h:Number,
     position_name:String,
     primary_pollutant:String,
     quality:String,
     so2:Number,
     so2_24h:Number,
     station_code:String,
     time_poNumber:String
});
mongoose.model('user', ListSchema,'atmosphere'); //将该Schema发布为Model,user就是集合名称
module.exports = mongoose;